# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=adassault
pkgver=0.0.3.r55.gfd9233e
pkgrel=1
groups=('blackarch' 'blackarch-networking')
pkgdesc='An Active Directory environments pentest tool complementary to existing ones like NetExec.'
arch=('any')
license=('MIT')
makedepends=('git')
# Tmp fix, requires erb explicitely https://gitlab.archlinux.org/archlinux/packaging/packages/ruby-erb/-/issues/1
depends=('ruby' 'ruby-bundler' 'ruby-erb')
url='https://noraj.github.io/ADAssault/'
source=("git+https://github.com/noraj/$pkgname.git")
sha512sums=('SKIP')
install="$pkgname.install"

pkgver() {
  cd $pkgname

  git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd $pkgname

  # bundle tries to solve conflicts and compatibilities issue even for EXCLUDED
  # gems (e.g. --without) commonmarker dev dependencies that we won't install
  # requires Ruby 3.1+ and current Ruby in AL is 3.0 (yes very outdated) so we
  # have to remove the dev dependencies from the Gemfile else we won't be able
  # to install without error
  sed -i '/group :development/,/end/d' Gemfile
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" *.md docs/**/*.md

  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm -rf docs/ *.md LICENSE

  cp --no-preserve=ownership -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec bundle exec ruby bin/$pkgname "\$@"
EOF

  cat > "$pkgdir/usr/bin/ada" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec bundle exec ruby bin/ada "\$@"
EOF

  chmod +x "$pkgdir"/usr/bin/*
}

